package com.glueball.crm.module.client.ui;

import com.glueball.crm.module.client.model.Contact;
import com.glueball.crm.module.common.ui.EditWidget;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class EditContactWidget extends EditWidget<Contact> {
	
	@UiField TextBox  titulus;
	@UiField TextBox  firstName;
	@UiField TextBox  lastName;
	@UiField CheckBox active;

	interface EditContactWidgetUiBinder extends	UiBinder<Widget, EditContactWidget> {
	}
	
	private static EditContactWidgetUiBinder uiBinder = GWT.create(EditContactWidgetUiBinder.class);

	public EditContactWidget(final Contact contact) {
		this.widget = uiBinder.createAndBindUi(this);
		setEntity(contact);
	}

	@Override
	public Contact getEntity() {
		this.entity.setTitulus(titulus.getText());
		this.entity.setFirstName(firstName.getText());
		this.entity.setLastName(lastName.getText());
		this.entity.setActive(active.getValue());
		return this.entity;
	}

	@Override
	public void setEntity(final Contact _entity) {
		this.entity = _entity;
		titulus.setText(entity.getTitulus());
		firstName.setText(entity.getFirstName());
		lastName.setText(entity.getLastName());
		active.setValue(entity.isActive());		
	}
}
